package com.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class HashMapTest {
    public static void main(String[] args) {
        Person person = new Person();
        person.setId(10);
        person.setName("张三");
        person.setSex("男");
        person.setHeight("175cm");
        person.setWeight("60kg");

        ArrayList<Person> arrayList = new ArrayList<>();
        arrayList.add(person);

        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("id", person.getId());
        hashMap.put("name", person.getName());
        hashMap.put("sex", person.getSex());
        hashMap.put("height", person.getHeight());
        hashMap.put("weight", person.getWeight());
        hashMap.put("recordList", arrayList);

        // 将 ArrayList 转换为 HashMap，并放入 personMap
        ArrayList<HashMap<String, Object>> recordList = new ArrayList<>();
        for (Person p : arrayList) {
            HashMap<String, Object> recordMap = new HashMap<>();
            recordMap.put("id", p.getId());
            recordMap.put("name", p.getName());
            recordMap.put("sex", p.getSex());
            recordMap.put("height", p.getHeight());
            recordMap.put("weight", p.getWeight());
            recordList.add(recordMap);
        }

        hashMap.put("recordList", recordList);

        for (Map.Entry<String, Object> objectEntry : hashMap.entrySet()) {
            String key = objectEntry.getKey();
            Object value = objectEntry.getValue();
            System.out.println(value);
        }
    }
}
